<?php

/**
 * This is the model class for table "topic".
 *
 * The followings are the available columns in table 'topic':
 * @property integer $id
 * @property integer $forumId
 * @property string $name
 * @property integer $iconId
 * @property integer $uacoId
 * @property integer $characterId
 * @property string $date
 * @property integer $stateId
 *
 * The followings are the available model relations:
 * @property Post[] $posts
 * @property Forum $forum
 * @property Icon $icon
 * @property Uacoptions $uaco
 * @property Character $character
 * @property State $state
 */
class Topic extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Topic the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'topic';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('forumId, iconId, uacoId, characterId, stateId', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>105),
			array('date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, forumId, name, iconId, uacoId, characterId, date, stateId', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'posts' => array(self::HAS_MANY, 'Post', 'topicId'),
			'forum' => array(self::BELONGS_TO, 'Forum', 'forumId'),
			'icon' => array(self::BELONGS_TO, 'Icon', 'iconId'),
			'uaco' => array(self::BELONGS_TO, 'Uacoptions', 'uacoId'),
			'character' => array(self::BELONGS_TO, 'Character', 'characterId'),
			'state' => array(self::BELONGS_TO, 'State', 'stateId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'forumId' => 'Forum',
			'name' => 'Name',
			'iconId' => 'Icon',
			'uacoId' => 'Uaco',
			'characterId' => 'Character',
			'date' => 'Date',
			'stateId' => 'State',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('forumId',$this->forumId);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('iconId',$this->iconId);
		$criteria->compare('uacoId',$this->uacoId);
		$criteria->compare('characterId',$this->characterId);
		$criteria->compare('date',$this->date,true);
		$criteria->compare('stateId',$this->stateId);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}